<template>
	<view class="mainpadding">
		<view class="" >
			<!-- 订单 -->
			<!-- <view class="ffffff mainpadding radius">
				<view class="ershiba zhonghei fonweight">订单编号：1245324564123132</view>
				<view class="flexbetween margin_top ">
					<image class="sptp" src="../static/images/system/bjc.png" mode=""></image>
					<view class="" style="width: 77%;">
						<view class="ershiba xiaohei yhxk">小天才-为你的熬夜肌肤注入神采5大...</view>
						<view class="strongtext xiaohui margin_top1">2023-10-07-2023-1208</view>
						<view class="flexbetween margin_top1">
							<view class="titletext xiaohong fonweight">¥98.00</view>
							<view class="ershil xiaocheng">x1</view>
						</view>
					</view>
				</view>
			</view> -->
			<!-- 发票 -->
			<!-- <view class="ffffff mainpadding radius margin_top">
				<view class="ershiba zhonghei fonweight">发票类型</view>
				<view class="flexleft margin_top">
					<view class="yxzbtn margin_right3">电子发票</view>
					<view class="wxzbtn ">增值税专用发票</view>
				</view>
			</view> -->
			<!-- 抬头类型 -->
			<view class="ffffff mainpadding radius">
				<view class="ershiba zhonghei fonweight">抬头类型</view>
				<view class="flexleft margin_top">
					<view class="margin_right3" :class="tt_type==1?'yxzbtn':'wxzbtn'" @click="tt_type=1">个人</view>
					<view :class="tt_type==2?'yxzbtn':'wxzbtn'" @click="tt_type=2">单位</view>
				</view>
			</view>
			<!--发票抬头  -->
			<view class="ffffff mainpadding radius margin_top flexbetween">
				<view class="ershiba zhonghei fonweight">发票抬头</view>
				<view class="flexright">
					<!-- <view class="ershiba xiaocheng margin_right1">林一贞</view> -->
					<input type="text" class="ershiba textright xiaocheng" placeholder="请输入发票抬头" v-model="name" name=""
						id="">
					<!-- <u-icon name="arrow-right" color="#999999"></u-icon> -->
				</view>
			</view>
			<!-- 如果选择单位展示的发票信息 -->
			<view class="ffffff mainpadding radius margin_top flexbetween" v-if="tt_type==1">
				<view class="ershiba zhonghei fonweight">电话</view>
				<input class="textright" type="number" placeholder="请输入电话" v-model="dwtel">
			</view>
			<view class="" v-if="tt_type==2">
				<view class="ffffff mainpadding radius margin_top flexbetween">
					<view class="ershiba zhonghei fonweight">单位税号</view>
					<input class="textright" type="text" placeholder="请输入单位税号" v-model="dwsh">
				</view>
				<view class="ffffff mainpadding radius margin_top flexbetween">
					<view class="ershiba zhonghei fonweight">开户银行</view>
					<input class="textright" type="text" placeholder="请输入开户银行" v-model="khyh">
				</view>
				<view class="ffffff mainpadding radius margin_top flexbetween">
					<view class="ershiba zhonghei fonweight">银行账号</view>
					<input class="textright" type="number" placeholder="请输入银行账号" v-model="yhzh">
				</view>
				<view class="ffffff mainpadding radius margin_top flexbetween">
					<view class="ershiba zhonghei fonweight">单位地址</view>
					<input class="textright" type="text" placeholder="请输入单位地址" v-model="dwdz">
				</view>
				<view class="ffffff mainpadding radius margin_top flexbetween">
					<view class="ershiba zhonghei fonweight">单位电话</view>
					<input class="textright" type="number" placeholder="请输入单位电话" v-model="dwtel">
				</view>
			</view>
		</view>
		<view class="gudingdb ffffff mainpadding">
			<view class="bigbtn" @click="submit()">提交</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tt_type: 1,
				name: "",
				dwsh: "",
				khyh: "",
				yhzh: "",
				dwdz: "",
				dwtel: "",
				listid:""
			}
		},
		onLoad(options) {
			if(options.id){
				uni.setNavigationBarTitle({
					title:"修改发票信息"
				})
				this.listid = options.id
				this.getDetail()
			}
		},
		methods: {
			getDetail(){
				httpRequest.request('/api/user/userTtDetail', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					let data = res.data
					this.tt_type = data.tt_type
					this.name = data.name
					this.dwsh = data.dwsh
					this.khyh = data.khyh
					this.yhzh = data.yhzh
					this.dwdz = data.dwdz
					this.dwtel = data.dwtel
				})
			},
			submit() {
				if(this.name==""){
					httpRequest.toast("请输入发票抬头")
					return false
				}
				if(this.tt_type==1){
					if(this.dwtel==""){
						httpRequest.toast("请输入电话")
						return false
					}
				}else{
					if(this.dwsh==""){
						httpRequest.toast("请输入单位税号")
						return false
					}
					if(this.khyh==""){
						httpRequest.toast("请输入开户银行")
						return false
					}
					if(this.yhzh==""){
						httpRequest.toast("请输入银行账号")
						return false
					}
					if(this.dwdz==""){
						httpRequest.toast("请输入单位地址")
						return false
					}
					if(this.dwtel==""){
						httpRequest.toast("请输入单位电话")
						return false
					}
				}
				let url = '/api/user/addUserTt'
				let data = {
					tt_type: this.tt_type,
					name: this.name,
					dwsh: this.dwsh,
					khyh: this.khyh,
					yhzh: this.yhzh,
					dwdz: this.dwdz,
					dwtel: this.dwtel,
					status: 0
				}
				if(this.listid){
					url = "/api/user/editUserTt"
					this.$set(data,"id",this.listid)
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.wxzbtn {
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		background: #f0f0f0;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid #f0f0f0;
		color: #666666;
		padding: 17rpx 20rpx;
	}

	.yxzbtn {
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		background: rgba(255, 147, 65, 0.1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid #FF9341;
		color: #FF9341;
		padding: 17rpx 20rpx;
	}

	.sptp {
		width: 124rpx;
		height: 124rpx;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
	}
</style>